<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
%>
<link href="<%=path%>/static/css/all.css?ehweee43" rel="stylesheet" type="text/css">
<header>

</header>
<body>
 <section>
    <div class="wrap">
        <article class="article">
            <div class="title">
                <h1>编辑材质信息</h1>
            </div>
            <form class="submitForm"  method="post" action="<%=path%>/backstage/garbage/updateTexture" enctype="multipart/form-data">
                <dl class="publish">
                    <dl>
                        <dt>一级材质</dt>
                        <dd>
                            <select class="type" name="texture.id" style="width: 360px;height: 30px;">
                                <option value="0">无</option>
                                <c:forEach items="${allTexture}" var="texture">
                                    <option value="${texture.id}">${texture.title}</option>
                                </c:forEach>
                            </select>
                        </dd>
                    </dl>
                    <dl>
                        <dt>图片</dt>
                        <dd>
                            <input style="height: 30px;" name="file" type="file">
                        </dd>
                    </dl>
                    <dl>
                        <dt>分类名称</dt>
                        <dd>
                            <input  style="height: 30px;"  class="titleTexture" name="title" value="${texture.title}" type="text">
                            <input name="id" type="hidden" value="${texture.id}">
                        </dd>
                    </dl>
                    <div class="submit">
                        <input type="button" onclick="checkAndSubmit()" value="提交">
                        <input type="reset" value="重置">
                    </div>
                </div>
            </form>
        </article>
    </div>
</section>
<script src="<%=path%>/static/js/layui/layui.all.js"></script>
<script src="<%=path%>/static/js/jquery-3.3.1.min.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="<%=path%>/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="<%=path%>/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('editorOnline', {
        toolbars: [
            [
                'bold',//加粗
                'italic',//斜体
                'superscript', //上标
                'subscript', //下标
                'indent', //首行缩进
                'simpleupload', //单图上传
                'link', //超链接
            ]
        ]
    });
    ue.ready(function () {
        ue.setHeight(200);
    })
</script>
<script>
    function childrenTexture(obj) {
        var texture = $(obj).val();
        if (texture == "") {
            $("#childrenTexture").html("");
        } else {
            $.ajax({
                url: "<%=path%>/web/texture/childrenTextures2",
                data: {texture: texture},
                type: "GET",
                success: function (data) {
                    $("#childrenTexture").html(data);
                }
            })
        }
    }
 //确认表单中数据
    function checkAndSubmit() {
        if ($(".titleTexture").val()== "") {//没写材质名称
            layer.msg("请输入材质名称", {icon: 5});
            return;
        }
        $(".submitForm").submit();

    }
</script>

<script>
    //给下拉列表框添加change事件，根据一级材质得到二级材质
    $(function () {
        $(".texture").change(function () {
            var textureId = $(this).val();
            $.get("<%=path%>/backstage/garbage/nextTextureData", {textureId: textureId}, function (mes) {
                $(".nextTexture").html(mes);
            });
        });
    });
</script>
</body>